package com.leyou.item.client;

import com.leyou.common.vo.PageResult;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient("item-service")
public interface ItemClient {

    /**
     * 基于品牌id查询品牌对象
     */
    @GetMapping("brand/{id}")
    public BrandDTO queryById(@PathVariable("id") Long id);

    /**
     * 基于分类id查询分类对象
     */
    @GetMapping("category/queryByCIds")
    public List<CategoryDTO> queryByCategoryIds(@RequestParam("ids") List<Long> ids);

    /**
     * 商品列表查询
     */
    @GetMapping("spu/page")
    public PageResult<SpuDTO> queryPage(
            @RequestParam(value = "key",required = false) String key,
            @RequestParam(value = "saleable",required = false) Boolean saleable,
            @RequestParam(value = "page",defaultValue ="1" ) Integer page,
            @RequestParam(value = "rows",defaultValue = "5") Integer rows
    );

    /**
     * 基于spuId查询spuDetail
     */
    @GetMapping("spu/detail")
    public SpuDetailDTO querySpuDetailBySpuId(@RequestParam("id") Long id);
    /**
     *  基于spuId查询sku列表
     */
    @GetMapping("sku/of/spu")
    public List<SkuDTO> querySkuBySpuId(@RequestParam("id") Long id);

    /**
     * 查询规格参数列表功能
     * gid:规格组id
     */
    @GetMapping("spec/params")
    public List<SpecParamDTO> querySpecParam(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean searching
    );

    /**
     * 基于品牌id集合查询品牌数据
     */
    @GetMapping("brand/queryBrandByIds")
    List<BrandDTO> queryBrandByIds(@RequestParam("ids") List<Long> ids);
    /**
     * 根据spuid查询spu 、spuDetail、skus
     */
    @GetMapping("spu/querySpuBySpuId/{id}")
    SpuDTO querySpuBySpuId(@PathVariable("id") Long id);
    /**
     * 根据分类查询规格组列表
     */
    @GetMapping("spec/querySpecGroupByCid/{cid}")
    List<SpecGroupDTO> querySpecGroupByCid(@PathVariable("cid") Long cid);

    @GetMapping("sku/list")
    List<SkuDTO> querySkuListByIds(@RequestParam("ids") List<Long> ids);
    /**
     * 扣减库存
     */
    @PutMapping("/stock/minus")
    void updateStock(@RequestBody Map<Long, Integer> skuMap);

    /**
     * 加库存
     * @param skuMap 商品id及数量的map
     */
    @PutMapping("/stock/plus")
    void plusStock(@RequestBody Map<Long, Integer> skuMap);

}
